/*
 * File:   FileLoggerTest.cpp
 * Author: Daniela
 *
 * Created on Mar 23, 2013, 9:45:02 PM
 */

#include "FileLoggerTest.h"
#define FILENAME "Logs.txt"


CPPUNIT_TEST_SUITE_REGISTRATION(FileLoggerTest);

FileLoggerTest::FileLoggerTest() {
}

FileLoggerTest::~FileLoggerTest() {
}

void FileLoggerTest::setUp() {
}

void FileLoggerTest::tearDown() {
    if (remove(FILENAME) != 0) {
        CPPUNIT_FAIL("The log file can't be deleted to start the test.");
    }
}

void FileLoggerTest::testFileLogger() {
    FileLogger* fileLogger = new FileLogger();
    char* defaultFileName = "Logs.txt";
    LoggingLevel level = INFO;
    CPPUNIT_ASSERT(fileLogger->getFile() != NULL);
    CPPUNIT_ASSERT(strcmp(defaultFileName, fileLogger->getFileName()) == 0);
    CPPUNIT_ASSERT_EQUAL(level, fileLogger->getLoggingLevel());
}

void FileLoggerTest::testLog() {
    FileLogger* fileLogger = new FileLogger();
    LoggingLevel level = INFO;
    unsigned int threadID = (unsigned int) pthread_self();
    const char* source = __PRETTY_FUNCTION__;
    char* msg = "Hello World";
    fileLogger->log(level, threadID, source, msg);

    FILE* file = fileLogger->getFile();
    fseek(file, 0, SEEK_END);
    long size = ftell(file);

    CPPUNIT_ASSERT(size != 0);
}

